package model.agent.question

import java.util.ArrayList;
import java.util.Collections;

class SingleSelectQuestion extends AbstractQuestion implements QuestionInterface{

	HashMap<String,Float> questions = [:]
	
	def valueSep = QuestionSet.valueSep
	
	def questionSep = QuestionSet.singleSep
	
	@Override
	public float answer(String ans) {

		ans = ans.trim().replace(" ","")
		if(questions.containsKey(ans)){
			lastResult = questions[ans]
			return lastResult
			
		}
		
		return 0;

	}

	/**
	 * 输入一个list，只看最后一个有效答案
	 */
	@Override
	public float answer(AbstractList ans) {
		float res = 0
		ans.each { String option ->
			if(questions.containsKey(option)){
				lastResult = questions[option]
				res = lastResult
			}
		}
		return res
	}

	@Override
	public ArrayList<String> getOptions() {
	
		return questions.keySet()
	}
	
	def SingleSelectQuestion(String qString){
		
		questionString = qString.replace(" ","").trim()
		def parts = questionString.split(questionSep)
		
		parts.each{
			def (q,v) = it.split(valueSep)
			questions[q]=v.toFloat()
		}
		
		
	}
	

}
